<?php
declare(strict_types=1);

namespace App\Resource\Streamer\Task;


use App\Enums\StreamerEnum;
use Illuminate\Http\Resources\Json\JsonResource;

class Resource extends JsonResource
{
    public function toArray($request)
    {
        $count = $this->template->type == StreamerEnum::TASK_TYPE_ONLINE ? floor($this->count / 3600) : $this->count;
        return [
            "id" => $this->id,
            "user_id" => $this->user_id,
            "date" => $this->date,
            "count" =>  $count,
            "target_count" => $this->target_count,
            "exp" => $this->exp,
            "status" => $this->status,
            "can_receive" => ($this->status == StreamerEnum::TASK_STATUS_FINISH && $this->rewards->isNotEmpty()) ? 1 : 0,
            "template" => TemplateResource::make($this->template),
            "rewards" => $this->rewards->isEmpty() ? null : RewardResource::collection($this->rewards),
        ];
    }
}